package com.wd.live.view.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.wd.live.R;
import com.wd.live.base.BaseActivity;
import com.wd.live.bean.GaiNameBean;
import com.wd.live.databinding.ActivityGaiNmaeBinding;
import com.wd.live.model.SpUtils;
import com.wd.live.model.utils.ToastFormat;
import com.wd.live.viewmodel.GaiNameViewModel;

import java.util.HashMap;
import java.util.Map;

public class GaiNmaeActivity extends BaseActivity<GaiNameViewModel, ActivityGaiNmaeBinding> {


    @Override
    protected void initData() {

        String nichengname = getIntent().getStringExtra("nichengname");
        Map<String, Object> map = new HashMap<>();
        String uid = SpUtils.getString("uid", "");
        String sid = SpUtils.getString("sid", "");
        int userid = Integer.parseInt(uid);
        map.put("sessionId",sid);
        map.put("userId",userid);
        databind.overnicheng.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = databind.nichengname.getText().toString();
                if(s!=null&&!nichengname.equals(s)){
                    viewmodel.gainamelist(map,s).observe(GaiNmaeActivity.this, new Observer<GaiNameBean>() {
                        @Override
                        public void onChanged(GaiNameBean gaiNameBean) {
                            ToastFormat.setText(gaiNameBean.getMessage());
                            ToastFormat.show();
                            if(gaiNameBean.getStatus().equals("0000")){
                                finish();
                            }
                        }
                    });
                }else {
                    Toast.makeText(GaiNmaeActivity.this, "不能为空", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

    @Override
    protected int initLayout() {
        return R.layout.activity_gai_nmae;
    }

    @Override
    public void onChanged(Object o) {

    }
}